{extend name="public/base"/}
{block name="style"}
    <link rel="stylesheet" href="/public/lboyue/m/css/loading.css">
	<script type="text/javascript" src="/public/lboyue/m/sitejs/book.js?v=20181123"></script>
	<script type="text/javascript">

		$(document).ready(function () {


			$('.moreIco').click(function () {

				if($(this).hasClass('closeIco')){

					$('#header').removeClass('app_headerFixed2');
					$(this).removeClass('closeIco');
					$('.app_header_second').hide();
					$('.app_meskSection').hide();

				}else{

					$('#header').addClass('app_headerFixed2');
					$(this).addClass('closeIco');
					$('.app_header_second').show();
					$('.app_meskSection').show();
				}



			})

			$('body').on('click','.app_meskSection',function () {
				$('.app_header_second').hide();
				$('.app_meskSection').hide();
				$('#header').removeClass('app_headerFixed2');
				$('.moreIco').removeClass('closeIco');
			})
		})

	</script>
{/block}
{block name="body"}
	<div class="app_goBackToTop"></div>
	<div class="app_meskSection"></div>

	<div class="container">

		<div class="app_header_section2  app_scrollerHeader" id="header">
			<div class="app_header_detail2">
				<div class="app_header_back"></div>
				<div class="app_header_h1">
					搜索结果<a href="/personal/bookcase"> <i class="shujiaIco"></i></a>
					<i class="moreIco"></i>
				</div>
			</div>
			{include file="public/dropnav" /}
		</div>
		   <div class="app_body">
        

    <div class="app_searchBlock  app_deleteMargin">
        <div class="app_searchBlock_bar">
            <input type="text" id="searchkeyword1" value="{$keyword}" placeholder="神医"/>
            <button class="button"  onclick="skipsearchbook(1)"></button>
        </div>
    </div>

        <div class="app_listBlock ">
        <div class="app_listBlock_con">
            <ul id="searchbookhtml">

			</ul>
        </div>

        <div class="app_reload" id="loading" style="display: none">
            <span class="loader-section">
                    <div class="loader-sectionContainer">
                        <div class="sk-fading-circle">
                            <div class="sk-circle1 sk-circle"></div>
                            <div class="sk-circle2 sk-circle"></div>
                            <div class="sk-circle3 sk-circle"></div>
                            <div class="sk-circle4 sk-circle"></div>
                            <div class="sk-circle5 sk-circle"></div>
                            <div class="sk-circle6 sk-circle"></div>
                            <div class="sk-circle7 sk-circle"></div>
                            <div class="sk-circle8 sk-circle"></div>
                            <div class="sk-circle9 sk-circle"></div>
                            <div class="sk-circle10 sk-circle"></div>
                            <div class="sk-circle11 sk-circle"></div>
                            <div class="sk-circle12 sk-circle"></div>
                        </div>
                    </div>
                    <div class="loader-sectionTips">正在加载更多</div>

                </span>
        </div>
        <div class="app_noData" style="display: none"><span class="noData">没有更多内容了</span></div>
    </div>

    {block name="include"}{include file="public:footer" /}{/block}
</div>


{/block}
{block name="script"}
   <script type="text/javascript" src="/public/lboyue/m/js/libs/jquerybase64.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/libs/jquery.json-2.4.min.js"></script>
    <script type="text/javascript" src="/public/lboyue/m/js/libs/jquery.cookie.js"></script>
	<!--------
    <script>
        // 请求数据页面
        var pageindex = 2;

        var keyword = "{$keyword}";

        var allowloadmore=true;
        // 还有没有数据
        var nodata =false;

        function loadMore() {
            if (nodata) {
                $(".app_noData").show();
                return "";
            }
			
            if(!allowloadmore) return;
			
            
            if (allowloadmore) {
                $('#loading').show();
                $.ajax({
                    url      : "/api/sou/index",
                    type     : "POST",
                    dataType : "json",
                    data     : {
                        "keyword" : keyword,
                        "page" : pageindex,
                    },
                    success  : function (re) {
                        $("#loading").hide();
                        var code = re.code;
                        switch (code)
                        {
                            case 1:
                                var books = re.data;
                                if (books.length > 0) {
                                    var html = "";
                                    for (var i=0; i < books.length; i++)
                                    {
                                        html += '<li>';
                                        html += '<a href="/book/'+data[i].id+'">';
                                        html += '<div class="leftImage"><img src="'+data[i].bookimg+'" /></div>';
                                        html += '<div class="rightBlock">';
                                        html += '<span class="rightBlock_title">'+data[i].bookname+'</span>';
                                        html += '<span class="rightBlock_con">';
                                        html += '<span class="con">'+data[i].formatbookintro+'</span>';
                                        html += '</span>';
                                        html += '<span class="rightBlock_label">';
                                        html += '<span class="keyWord_l">';
                                        html += '<i class="k1">'+data[i].endstatusstr+'</i>'
                                        html += '</span>';
                                        html += '<span class="keyWord_r">';
                                        html += '<i class="k1">'+data[i].bookcntwan+'万字</i>';
                                        html += '<i class="k2">'+data[i].shortname+'</i>';
                                        html += '</span>';
                                        html += '</span>';
                                        html += '</div>';
                                        html += '</a>';
                                        html += '</li>';
                                    }
                                    $("#searchbookhtml").append(html);
                                    if (books.length < 10) {
                                        allowloadmore = false;
                                        nodata = true;
                                        $(".app_noData").show();
                                    } else if (books.length = 10) {
                                        pageindex = pageindex + 1;
                                    }

                                }
                                break;
                            case 3:
                                allowloadmore = false;
                                malert(re.message);
                                break;
                            case 999:
                                allowloadmore = false;
                                $(".app_noData").show();
                                break;
                            default:
                                allowloadmore = false;
                                malert(re.message);
                                break;
                        }
                    },
                    error    : function () {
                        allowloadmore = true;
                        malert("服务器开小差了～");
                        return "";
                    }
                });

            }
        }

        $(document).ready(function () {

            $(window).scroll(function () {
				
                loadMore();
            });

            document.addEventListener('touchstart',function () {
                loadMore();
            },false);

            document.addEventListener('touchmove',function () {
                loadMore();
            },false);

            document.addEventListener('touchend',function () {
                loadMore();
            },false);

        });


        // 记录搜索值
        var searchkey = "wapsearch";
        var searchvalue = $.cookie(searchkey);
        var searchkeyword = $("#searchkeyword1").val();
        if (searchkeyword == "" || searchkeyword == undefined) {
            searchkeyword = $("#searchkeyword2").val();
        }
        var DeveloperMode = "";
        var domain = "{$Think.config.web_pc_url|str_replace="http://www","",###}";
        if (searchkeyword != "") {
            if (searchvalue != undefined) {
                var searchnumber = 10;
                var searchvaluearr = searchvalue.split(",");

                for (var i = 0; i< searchvaluearr.length; i++) {

                    if (searchvaluearr[i] == searchkeyword) {

                        // 删除掉
                        searchvaluearr.splice(i, 1);
                        break;
                    }
                }


                if (searchvaluearr.length > searchnumber ) {
                    searchvaluearr.splice(0,1);
                }
                if (searchvaluearr.length > 0) {
                    searchvalue = searchvaluearr.join(",");
                    searchvalue = searchkeyword+","+searchvalue;
                } else {
                    searchvalue = searchkeyword;
                }


            } else {
                searchvalue = searchkeyword;
            }
            var expires = 365;

            if (DeveloperMode == "1") {
                $.cookie(searchkey, searchvalue, {expires: expires, path: '/'});
            } else {
                $.cookie(searchkey, searchvalue, {expires: expires,domain:domain, path: '/'});
            }
        }


    </script>
	------->
	<script type="text/javascript">
		var start=1,
			sBookstop=true, 
			sBookstopTime=null, 
			pagesize=10;
		var keyword = "{$keyword}";

		$(function(){
			loadingList();
			$(window).scroll(function(){
				var nWinH =  document.documentElement.clientHeight;
				var nScrollTop = (document.body.scrollTop || document.documentElement.scrollTop) + nWinH;
				var nBodyScrollH = document.body.scrollHeight;
				if(sBookstop && nBodyScrollH - nScrollTop < 240){
					bookstoptime();
					$('#loading').show();
					$('.app_noData').hide();
					loadingList();
				}
			});
		});

		function loadingList(){
			$.ajax({
				type: 'post',
				url: '/api/sou/index/',
				timeout: 500,
				cache: false,
				dataType: 'json',
				data: {
					'keyword':keyword,
					'page': start,
				},
				success: function (json) {
					var data=json.data;
					clearTimeout(sBookstopTime);
					if (typeof data == 'string') {
						data = JSON.parse(data);
					}
					if(data<=0 && pagenum == 1){
						$('#loading').hide();
						$('.app_noData').show();
						sBookstop = false;
						return false;
					}
					if (data.length > 0) {
						var html = "";
						var fullflag = "";
						for (var i=0; i < data.length; i++)
						{
							if(data[i].fullflag==1){
								fullflag="完结";
							}else{
								fullflag="连载中";
							}


							html += '<li>';
							html += '<a href="/book/info/id/'+data[i].id+'">';
							html += '<div class="leftImage"><img src="'+data[i].cover+'" onerror="javascript:this.src=\'/public/novel/images/default.jpg\';"/></div>';
							html += '<div class="rightBlock">';
							html += '<span class="rightBlock_title">'+data[i].title+'</span>';
							html += '<span class="rightBlock_con">';
							html += '<span class="con">'+data[i].intro+'</span>';
							html += '</span>';
							html += '<span class="rightBlock_label">';
							html += '<span class="keyWord_l">';
							html += '<i class="k1">'+fullflag+'</i>'
							html += '</span>';
							html += '<span class="keyWord_r">';
							html += '<i class="k1">'+data[i].size+'万字</i>';
							html += '<i class="k2">'+data[i].category+'</i>';
							html += '</span>';
							html += '</span>';
							html += '</div>';
							html += '</a>';
							html += '</li>';
						}
						$("#searchbookhtml").append(html);


					}
					start =start+1; 
					if(data.length<10){
						$('.app_noData').show();
						$('#loading').hide();
						sBookstop = false;
					}else{
						$('#loading').show();
						$('.app_noData').hide();
						sBookstop = true;
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					$('.app_noData').show();
					$('#loading').hide();
					sBookstop = false;
				}
			});
		}

		//防止重复请求数据
		function bookstoptime() {
			clearTimeout(sBookstopTime);
			sBookstop = false;
			sBookstopTime = setTimeout(function () {
				sBookstop = true;
			}, 3000);
		}
	</script>

{/block}